package com.mtl.user.service.impl;

import com.mtl.user.domain.User;
import com.mtl.user.mapper.UserMapper;
import com.mtl.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.mtl.common.tool.model.Page;

import java.util.List;
/**
 * 用户管理 服务实现类
 *
 * @author qms
 * @since 2019-08-06
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User findById(Integer id) {
        return userMapper.selectByPrimaryKey(id);
    }

    @Override
    public Page<User> findPage(Integer page, Integer size,String search) {
        PageHelper.startPage(page,size);
        List<User> user=userMapper.selectByCondition(search);
        return new Page<>(user);
    }
    @Override
    public Page<User> findName(String search) {
        PageHelper.startPage(1,1000);
        List<User> user=userMapper.selectByNameAs(search);
        return new Page<>(user);
    }
    @Override
    public int saveOrUpdate(User user) {
        if(user.getId()!=null){
        return userMapper.updateByPrimaryKey(user);
        }
        return userMapper.insert(user);
    }

    @Override
    public int deleteBatch(List<Integer> ids) {
        return userMapper.deleteByIdList(ids);
    }

    @Override
    public User login(String userName, String password) {
        return userMapper.selectUserNameAndPassword(userName,password);
    }
}
